package ui;

import a4.Controller;
import a4.Main;
import data.Offer;
import java.util.ArrayList;
import user.Customer;

class CustomerUI extends UI {

    CustomerUI(Customer costumer) {
        user = costumer;
    }

/**
     * CustomerUI customerMenu()
     * 
     * "Provoli tou menou tou pelati, kathws kai dinatotita na proxwrisei sta ypomenou"
     */

    public void customerMenu() {
        do {
            System.out.println("1.New order\n"
                    + "2.Print orders\n"
                    + "3.Logout\n");
            choise = input.next();
            if (choise.equals("1"))
                order();
            else if (choise.equals("2"))
                return;
            else if (choise.equals("3"))
                logout();
            else
                System.out.print("\nPlease choose a valid option.\n");
        }
        while (!choise.equals("3"));
    }

/**
     * CustomerUI order()
     * 
     * "Provoli tou menou gia pragmatopoiisi kainourias paraggelias."
     */



    private void order() {
        printProductList();
        ArrayList<Integer> selectedProducts = new ArrayList<Integer>();
        System.out.print("Select your products. When done, press enter.");
        //String tmp=Main.productList.size();
           int choise2 = readInt("Select your products. When done, press enter.", "Mh yparkto proion!", 0,Main.productList.size());
        Offer offer = Controller.getOffer( selectedProducts );
        if (offer != null){
            System.out.print("You have won the following offer!");
            System.out.printf("Item: %s",offer.getItem() );
        }
        System.out.print("Press y/n to confirm the order: ");
        if ( input.next().equalsIgnoreCase("n") ) return;
        Controller.addOrder( (Customer) user, selectedProducts, offer );
        System.out.print("Your offer has been completed.\n");
    }
}